import 'package:flutter_blue_plus/flutter_blue_plus.dart';

class DeviceConnect {
  String get macId => device?.remoteId.str ?? '';
  String get name => device?.platformName ?? '';

  Stream<BluetoothConnectionState> get connectionState =>
      device!.connectionState;

  BluetoothDevice? device;

  BluetoothCharacteristic? writeService;
  BluetoothCharacteristic? readService;
  BluetoothCharacteristic? otherService;
  Guid? serviceUuid;
  Guid? writeUuid;
  Guid? readUuid;
  Guid? otherUuid;

  bool? setNotify;

  bool get isConnected => device?.isConnected ?? false;

  DeviceConnect({
    this.device,
    this.serviceUuid,
    this.writeService,
    this.readService,
    this.writeUuid,
    this.readUuid,
    this.otherService,
    this.setNotify,
    this.otherUuid,
  });

  Future<void> disconnect() async {
    await device?.disconnect();
    writeService = null;
    readService = null;
    otherService = null;
  }
}
